<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>后台管理 - 易买网</title>
<link type="text/css" rel="stylesheet" href="../css/style.css" />
<script type="text/javascript" src="../scripts/jquery-1.8.3.js"></script>
</head>
<body>
<div class="main">
	<h2>修改用户</h2>
	<div class="manage">
		<form action="UserModifyServlet" method="post">

			<table class="form">
				<tr>
					<td class="field">登陆名:</td>
					<td><input type="text" name="username" value="${user.username}"></td>
				</tr>
				<tr>
					<td class="field">用户名:</td>
					<td><input type="text" name="userusername" value="${user.userusername}"></td>
				</tr>

				<tr>
					<td class="field">用户密码:</td>
					<td><input type="password" name="userpwd" value="${user.userpwd}"></td>
				</tr>
				<tr>
					<td class="field">家庭地址:</td>
					<td><input type="text" name="useraddress" value="${user.useraddress}"></td>
				</tr>
				<tr>
					<td class="field">邮箱:</td>
					<td><input type="text" name="useremail" value="${user.useremail}"></td>
				</tr>
				<tr>
					<td class="field">出生日期:</td>
					<td><select id="birth_year" onchange="setDays(this,birth_month,birth_day);">
						<option value="">年</option>

					</select> <select id="birth_month" onchange="setDays(birth_year,this,birth_day);">
						<option value="">月</option>

					</select> <select id="birth_day">
						<option value="">日</option>

					</select></td>
				</tr>
				<tr>
					<td class="field">权限管理::</td>
					<td><input type="radio" name="userflag" value="1" checked="checked" />普通用户 <input type="radio" name="userflag" value="1" />管理员</td>
				</tr>
				<tr>
					<td class="field">头像:</td>
					<td><input type="file" class="text" name="photo" /></td>
				</tr>
				<tr>
					<td></td>
					<td><label class="ui-blue"><input type="submit" name="submit" value="更新" /></label></td>
				</tr>
				<input type="hidden" value="${user.userid}" name="userid"/>
			</table>

			<input type="submit" value="确认修改完毕">
		</form>


	</div>
</div>
</body>
</html>
<script>

    $(document).ready(function() {
        var i = -1;
        // 添加年份,从1910年开始
        for (i = 1910; i <= new Date().getFullYear(); i++) {
            addOption(birth_year, i, i - 1909);
            /*// 默认选中1988年
            if (i == 1988) {
                birth_year.options[i-1910].selected = true;
            }*/
        }
        // 添加月份
        for (i = 1; i <= 12; i++) {
            addOption(birth_month, i, i);
        }
        // 添加天份,先默认31天
        for (i = 1; i <= 31; i++) {
            addOption(birth_day, i, i);
        }



        //$("#birth_month"). birth_year  birth_day
    });


    // 设置每个月份的天数
    function setDays(year, month,day) {
        var monthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
        var yea = year.options[year.selectedIndex].text;
        var mon = month.options[month.selectedIndex].text;
        var num = monthDays[mon - 1];
        if (mon == 2 && isLeapYear(yea)) {
            num++;
        }
        for (var j = day.options.length - 1; j >=num; j--) {
            day.remove(j);
        }
        for (var i = day.options.length; i <= num; i++) {
            addOption(birth_day,i,i);
        }
    }

    // 判断是否闰年
    function isLeapYear(year)
    {
        return (year % 4 == 0 || (year % 100 == 0 && year % 400 == 0));
    }

    // 向select尾部添加option
    function addOption(selectbox, text, value) {
        var option = document.createElement("option");
        option.text = text;
        option.value = value;

        selectbox.options.add(option);
    }

</script>